home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1263
/
fxt.cb
< prev
next >
Wrap
Text File
|
1997-04-18
|
43KB
|
1,262 lines
/*****************************************************************************/
/*
FXT.CB - BRIEF MACRO FUNCTIONS FOR
FFTN (TM) FORTRAN FUNCTION TREE NAVIGATOR
Copyright (C) Juergen Mueller (J.M.) 1992-1996
All rights reserved.
You are expressly prohibited from selling this software in any form,
distributing it with another product, or removing this notice.
Limited permission is given to registered FXT users to modify this
file for their own personal use only. This file may not be used for any
purpose other than in conjunction with the FXT software package.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE
IMPLIED WARRANTIES OF MERCHANTIBILITY OR FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
PROGRAM AND DOCUMENTATION IS WITH YOU.
written by: Juergen Mueller, Aldingerstrasse 22, D-70806 Kornwestheim,
GERMANY
FILE : FXT.CB
REVISION : 27-Apr-1996
18:31:07
*/
/*****************************************************************************/
#include "dialog.h" /* include file from original BRIEF DIALOG menus */
/*****************************************************************************/
/* defines */
/*****************************************************************************/
#define TMPFILE "FXTFILE.TMP"
#define FFTNPROG "fftn" /* or "fftn4os2" for OS/2 */
/* or "fftn32" for Windows NT / Windows 95 */
#ifdef __OS2__
#define upper(x) (x)
#endif
/*****************************************************************************/
/**** USER macro function prototypes ****/
/*****************************************************************************/
void fft(void);
void fftfind(void);
void fftmenu(void);
void fftbase(void);
void fftfilemenu(void);
void fftxrefmenu(void);
void fftxrefmenuagain(void);
void fftdefmenu(void);
/*****************************************************************************/
/**** INTERNAL macro function prototypes ****/
/*****************************************************************************/
void _init(void); /* initialisation function, called on entry */
void _fxtmenu_exit(void);
void _exec_error(int retval, string format, string par1, string par2);
string _extract_item(void);
void _fxt(string, string);
void _fxt_search(string, string, string, int, int);
void _fxt_edit_file(void);
void _fxt_locate(void);
void _fxt_buffers(void);
void _fxtmenu(string, string);
int _fft_action(int, ...);
void _fxtfilemenu(string, string);
int _fxt_fileaction(int, ...);
void _fxtxrefmenu(string, string, int);
int _fxt_xrefaction(int, ...);
void _fxtdefmenu(string, string);
int _fxt_defaction(int, ...);
void _fxt_insert_sorted(string, int, int);
/*****************************************************************************/
/**** global variables ****/
/*****************************************************************************/
string fft_base; /* data base name for fft */
string fxt_loc; /* resulting file with item location */
string fxt_item; /* item to search for */
int fxt_id; /* item id */
string fxt_file; /* target file name */
int fxt_line; /* target line, used by registered macro */
string fft_loc; /* resulting file for menu */
int fft_menuwidth; /* horizontal fft menu width */
string fft_files; /* resulting file for filemenu */
int fft_filemenuwidth; /* horizontal fft filemenu width */
string fft_xref;
string fft_xref_item;
int fft_xrefmenuwidth;
string fft_deffile;
string fft_def_item;
int fft_defmenuwidth;
/*****************************************************************************/
/**** macro package initialization function ****/
/*****************************************************************************/
void _init(void)
{
/* init FFT base with environment */
fft_base = trim(ltrim(inq_environment("FFTNBASE")));
fxt_loc = "fxt.loc"; /* intermediate file for search results */
fft_loc = "fft.loc"; /* used for function menu */
fft_files = "fft_file.loc"; /* used for function file menu */
fft_xref = "fft_xref.loc";
fft_xref_item = "";
fft_deffile = "fft_def.loc";
fft_def_item = "";
/* register macro to delete temporary files on exit from BRIEF */
register_macro(5, "_fxtmenu_exit");
}
/*****************************************************************************/
/* registered macro to perform actions on exit of BRIEF or */
/* if changes of database names have happened */
/*****************************************************************************/
void _fxtmenu_exit(void)
{
if (exist(fft_loc))
del(fft_loc);
if (exist(fft_files))
del(fft_files);
if (exist(fft_xref))
del(fft_xref);
if (exist(fft_deffile))
del(fft_deffile);
}
/*****************************************************************************/
/**** user callable macros ****/
/*****************************************************************************/
void fft(void) /* find function */
{
_fxt(FFTNPROG, fft_base); /* do function retrieval */
}
void fftfind(void) /* find user defined item */
{
string item;
get_parm(NULL, item, "FFT function name: ", 50);
item = compress(trim(ltrim(item)));
if (strlen(item))
_fxt_search(FFTNPROG, fft_base, item, 0, 0);
}
void fftmenu(void) /* build function menu */
{
_fxtmenu(FFTNPROG, fft_base);
}
void fftbase(void) /* set FFT database name */
{
get_parm(NULL, fft_base, "FFT database name: ", 50, fft_base);
fft_base = trim(ltrim(fft_base));
_fxtmenu_exit(); /* delete menu files */
}
void fftfilemenu(void) /* build FFT file menu */
{
_fxtfilemenu(FFTNPROG, fft_base);
}
void fftxrefmenu(void) /* build function cross reference menu */
{
_fxtxrefmenu(FFTNPROG, fft_base, 1);
}
void fftxrefmenuagain(void) /* rebuild menu for previous item */
{
_fxtxrefmenu(FFTNPROG, fft_base, 0);
}
void fftdefmenu(void)
{
_fxtdefmenu(FFTNPROG, fft_base);
}
/*****************************************************************************/
/**** internal macro execution functions ****/
/*****************************************************************************/
/*****************************************************************************/
/* */
/*****************************************************************************/
void _exec_error(int retval, string format, string par1, string par2)
{
if (retval >= 100)
message(format, par1, par2);
else
message("Command execution error (%d)", retval);
}
/*****************************************************************************/
/* read search item from current buffer */
/*****************************************************************************/
string _extract_item(void)
{
int move_flag, markval, marklen;
int start_line, start_col, end_line, end_col;
string itemname, act_char, tmp_char, fchar, nchar;
fchar = "[$_a-zA-Z]"; /* first character of an identifier */
nchar = "[$_a-zA-Z0-9]"; /* not first character of an identifier */
if (!(markval = inq_marked(start_line, start_col, end_line, end_col)))
{ /* nothing marked, use cursor position */
if (!search_string(nchar, read(1)))
{
message("Invalid cursor position");
return "";
}
save_position(); /* save the current position */
act_char = read(1); /* read current character */
while (search_string(nchar, act_char))
{ /* move backward to first character */
if (!prev_char(1))
{
move_flag = 1;
break;
}
act_char = read(1);
}
if (!move_flag)
next_char(1); /* one step forward */
act_char = read(1); /* read current character */
if (!search_string(fchar, act_char)) /* test first identifier character */
{
message("Invalid cursor position");
return "";
}
while (search_string(nchar, act_char))
{
itemname += act_char; /* generate identifier name */
next_char(1);
act_char = read(1);
}
restore_position(); /* restore old position */
}
else if (markval == 1) /* marked area found, read contents in */
{
marklen = inq_mark_size(); /* number of characters */
if ((start_line != end_line) || (marklen > 60))
{
message("Invalid marked block");
mark(); /* remove mark */
return "";
}
save_position(); /* save the current position */
move_abs(start_line, start_col);
while (marklen--) /* read marked block */
{
itemname += read(1);
next_char(1);
}
restore_position(); /* restore old position */
mark(); /* remove mark */
}
else
{ /* markval not 0 or 1, error */
message("Invalid cursor position");
return "";
}
if (index(itemname, "\t")) /* exchange tabs with blanks */
{
act_char = ""; /* temporary storage location */
end_col = strlen(itemname);
for (start_col = 1; start_col <= end_col; ++start_col)
{
tmp_char = substr(itemname, start_col, 1);
act_char += (tmp_char == "\t") ? " " : tmp_char;
}
itemname = act_char; /* restore processed name */
}
return compress(ltrim(trim(itemname))); /* compress whitespace */
}
/*****************************************************************************/
/* perform data base search with item from current buffer */
/*****************************************************************************/
void _fxt(string fxt_func, /* fxt function to perform */
string fxt_base /* fxt base to search */
)
{
string itemname;
itemname = _extract_item();
if (strlen(itemname))
_fxt_search(fxt_func, fxt_base, itemname, 0, 1); /* do database search */
}
/*****************************************************************************/
/* the database retrieval function */
/*****************************************************************************/
void _fxt_search(string fxt_func, /* fxt action to perform */
string fxt_base, /* fxt base name to search */
string itemname, /* item to search for */
int itemid, /* item id */
int uflag /* underline flag */
)
{
int old_buffer, loc_buffer, dos_ret;
string act_char, linestring, cmd;
/* test for function search and identifier with leading underline */
if ((fxt_func == FFTNPROG) && uflag && (substr(itemname, 1, 1) == "_"))
{
inq_names(NULL, act_char, NULL); /* get file extension */
act_char = lower(act_char);
/* test, if we are inside of an assembler file: extension "asm" or "s" */
if ((act_char == "asm") || (act_char == "s"))
{ /* prompt user for choice */
get_parm(NULL, act_char, "Remove leading underline before search [y/n]? ", 1, "y");
if (lower(act_char) == "y")
itemname = substr(itemname, 2); /* remove leading underline */
}
}
message("Searching for '%s'", itemname); /* show what's going on */
/* DATABASE SEARCH */
/* build command line string, the following arguments are used: */
/* -b: batch mode */
/* -f: database name */
/* -r: record id number */
sprintf(cmd, "%s -b -r%d ", fxt_func, itemid);
if (strlen(fxt_base))
cmd += "-f" + fxt_base + " ";
if (index(itemname, " ")) /* if itemname is more than one word */
cmd += "\"" + itemname + "\""; /* quote itemname */
else
cmd += itemname;
cmd += " >&" + fxt_loc;
dos_ret = dos(cmd); /* look for reqested identifier in database */
if (dos_ret == 102) /* item found, but database not up-to-date */
get_parm(NULL, act_char, "Database not up-to-date! (press any key)", 1);
else if (dos_ret != 101)
{ /* item not found */
_exec_error(dos_ret, "%s '%s' not found", "Function", itemname);
del(fxt_loc); /* delete file */
return; /* and return */
}
/* item found, prepare for opening the related source file */
old_buffer = inq_buffer(); /* read result from file */
loc_buffer = create_buffer(fxt_loc, fxt_loc, 1);
if (!loc_buffer) /* if file buffer not present */
return; /* return */
set_buffer(loc_buffer); /* change working buffer */
act_char = read(1); /* read filename from buffer */
if (act_char == "\n") /* file empty ? */
{
set_buffer(old_buffer); /* restore old buffer */
delete_buffer(loc_buffer); /* delete working buffer */
del(fxt_loc); /* delete file */
message("%s '%s' not defined", "Function", itemname);
return;
}
fxt_file = ""; /* initialize file name */
fxt_line = 1; /* initialize line number */
while (!index(" ", act_char)) /* loop over file name */
{
fxt_file += act_char;
next_char(1);
act_char = read(1);
}
next_char(1); /* skip blank */
act_char = read(1); /* read line number */
while (!index("\r\n", act_char)) /* loop over line number */
{
linestring += act_char;
next_char(1);
act_char = read(1);
}
fxt_line = atoi(linestring); /* convert to integer */
set_buffer(old_buffer); /* restore old buffer */
delete_buffer(loc_buffer); /* delete working buffer */
del(fxt_loc); /* delete file */
_fxt_edit_file(); /* open file for edit */
}
/*****************************************************************************/
/* macro for opening file for edit, executed for every file */
/*****************************************************************************/
void _fxt_edit_file(void)
{
if (!exist(fxt_file)) /* test if file does exist */
message("Missing file: %s", fxt_file); /* if not, just give message */
else
{ /* file exists */
message(""); /* clear message area */
_fxt_buffers(); /* look for requested file buffer */
register_macro(6, "_fxt_locate"); /* register macro for "edit_file()" */
edit_file(fxt_file); /* display requested file */
unregister_macro(6, "_fxt_locate"); /* unregister macro */
}
}
/*****************************************************************************/
/* registered macro for invocation of "edit_file()" */
/*****************************************************************************/
void _fxt_locate(void)
{
goto_line(fxt_line); /* go to line with searched item */
refresh(); /* redraw window */
}
/*****************************************************************************/
/* check all buffers if requested file is already in buffer list */
/*****************************************************************************/
void _fxt_buffers(void)
{
int curr_buf, old_buf;
string filename;
old_buf = inq_buffer(); /* actual working buffer */
curr_buf = old_buf; /* remember actual buffer */
do /* loop through all buffers to find requested file */
{
inq_names(filename); /* buffer filename */
if (index(upper(filename), upper(fxt_file)))
{
goto_line(fxt_line); /* buffer is present, go to line */
refresh(); /* redraw window */
break; /* stop looping */
}
curr_buf = next_buffer(); /* get next buffer */
set_buffer(curr_buf); /* make buffer active */
} while (curr_buf != old_buf); /* loop through all buffers */
if (curr_buf != old_buf) /* if current buffer has changed */
set_buffer(old_buf); /* restore first buffer */
}
/*****************************************************************************/
/* dialog menu generation front end for fxt items */
/*****************************************************************************/
void _fxtmenu(string fxt_func, string fxt_base)
{
int menu_buf, old_buf_id, line, width, max_width;
int num_lines, num_cols, dos_ret;
string fxt_param, fxt_action, item, file;
item = "FFT function"; /* FFT function search */
file = fft_loc;
max_width = fft_menuwidth;
fxt_action = "_fft_action"; /* keystroke action */
message("Building %s menu", item);
if (!exist(file)) /* if menu file does not exist, build it */
{
/* DATABASE SEARCH */
if (strlen(fxt_base))
fxt_param = " -f" + fxt_base + " ";
dos_ret = dos(fxt_func + " -B " + fxt_param + "* >&" + file);
if (dos_ret != 101)
{
_exec_error(dos_ret, "No %s found", item, NULL);
del(file); /* delete file */
return;
}
max_width = 0; /* reset value */
}
fxt_item = ""; /* reset variable */
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer(item, file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
top_of_buffer(); /* go to top */
if (!max_width) /* if first call, maximum width is unknown */
{
while (!inq_position()) /* read every entry to get maximum width */
{
message("Building %s menu [#%d]", item, ++line);
fxt_item = trim(read()); /* read item */
fxt_item = substr(fxt_item, 1, rindex(fxt_item, "\t") - 1);
width = strlen(fxt_item);
if (width > 1)
{
if (width > max_width)
max_width = width; /* store maximum */
}
end_of_line(); /* go til end of line and ... */
next_char(1); /* wrap around end of line */
}
fft_menuwidth = max_width;
}
else /* consecutive call, perform default action */
{
end_of_buffer(); /* go to end of buffer */
next_char(1); /* go one character beyond the end because */
/* it must be one line more than items */
}
inq_position(line); /* get current position */
top_of_buffer(); /* go to top of buffer */
fxt_item = ""; /* reset variable */
fxt_id = 0;
if ((line > 1) && max_width) /* if any entries found */
{ /* start building dialog menu */
tabs(132); /* set new tab size to split informations */
inq_screen_size(num_lines, num_cols);
if ((line += 3) > (num_lines - 5))
line = num_lines - 5;
if ((max_width += 2) < 15)
max_width = 15;
if (max_width >= num_cols - 3)
max_width = num_cols - 3;
max_width = (max_width + 1) / 2; /* calculate menu window sizes */
num_cols = (num_cols + 1 ) / 2;
set_buffer(old_buf_id); /* restore old buffer */
/* call dialog menu processing function */
_process_menu(num_cols - max_width,
line,
num_cols + max_width,
3,
NULL,
"",
NULL,
menu_buf, /* buffer to use for dialog menu */
fxt_action, /* function to perform on keystroke */
TRUE
);
}
else /* no entries found */
{
set_buffer(old_buf_id); /* restore old buffer */
message("No %s found", item);
}
delete_buffer(menu_buf); /* delete buffer from list */
if (strlen(fxt_item)) /* if item selected from menu */
_fxt_search(fxt_func, fxt_base, fxt_item, fxt_id, 0); /* search and display item */
}
/*****************************************************************************/
/* registered macro to perform fft actions for menu keystrokes */
/*****************************************************************************/
int _fft_action(int event_type, ...)
{
string button_text;
get_parm(NULL, event_type);
switch (event_type)
{
case DIALOG_PICK_MENU:
case DIALOG_F10:
{
get_parm(2, button_text); /* get item name to search for */
fxt_item = substr(button_text, 1, rindex(button_text, "\t") - 1);
fxt_id = atoi(substr(button_text, rindex(button_text, "\t") + 1));
_dialog_esc(); /* leave menu procedure */
}
}
returns(TRUE);
}
/*****************************************************************************/
/* dialog menu generation front end for fxt files */
/*****************************************************************************/
void _fxtfilemenu(string fxt_func, string fxt_base)
{
int menu_buf, old_buf_id, line, width, max_width;
int num_lines, num_cols, dos_ret;
string fxt_param, item, file;
item = "FFT file";
file = fft_files;
max_width = fft_filemenuwidth;
message("Building %s menu", item);
if (!exist(file)) /* if menu file does not exist, build it */
{
/* DATABASE SEARCH */
if (strlen(fxt_base))
fxt_param = " -f" + fxt_base + " ";
dos_ret = dos(fxt_func + " -F " + fxt_param + "* >&" + file);
if (dos_ret != 101)
{
_exec_error(dos_ret, "No %s found", item, NULL);
del(file); /* delete file */
return;
}
max_width = 0; /* reset value */
}
fxt_item = ""; /* reset variable */
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer(item, file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
top_of_buffer(); /* go to top */
if (!max_width) /* if first call, maximum width is unknown */
{
while (!inq_position()) /* read every entry to get maximum width */
{
message("Building %s menu [#%d]", item, ++line);
fxt_item = trim(read()); /* read item */
width = strlen(fxt_item);
if (width > 1)
{
if (width > max_width)
max_width = width; /* store maximum */
}
end_of_line(); /* go til end of line and ... */
next_char(1); /* wrap around end of line */
}
fft_filemenuwidth = max_width;
}
else /* consecutive call, perform default action */
{
end_of_buffer(); /* go to end of buffer */
next_char(1); /* go one character beyond the end because */
/* it must be one line more than items */
}
inq_position(line); /* get current position */
top_of_buffer(); /* go to top of buffer */
fxt_item = ""; /* reset variable */
if ((line > 1) && max_width) /* if any entries found */
{ /* start building dialog menu */
tabs(132); /* set new tab size to split informations */
inq_screen_size(num_lines, num_cols);
if ((line += 3) > (num_lines - 5))
line = num_lines - 5;
if ((max_width += 2) < 15)
max_width = 15;
if (max_width >= num_cols - 3)
max_width = num_cols - 3;
max_width = (max_width + 1) / 2; /* calculate menu window sizes */
num_cols = (num_cols + 1 ) / 2;
set_buffer(old_buf_id); /* restore old buffer */
/* call dialog menu processing function */
_process_menu(num_cols - max_width,
line,
num_cols + max_width,
3,
NULL,
"",
NULL,
menu_buf, /* buffer to use for dialog menu */
"_fxt_fileaction", /* function to perform on keystroke */
TRUE
);
}
else /* no entries found */
{
set_buffer(old_buf_id); /* restore old buffer */
message("No %s found", item);
}
delete_buffer(menu_buf); /* delete buffer from list */
if (strlen(fxt_item)) /* if item selected from menu */
{
fxt_line = 1;
fxt_file = fxt_item;
_fxt_edit_file(); /* open file for edit */
}
}
/*****************************************************************************/
/* registered macro to perform actions for menu keystrokes */
/*****************************************************************************/
int _fxt_fileaction(int event_type, ...)
{
string button_text;
get_parm(NULL, event_type);
switch (event_type)
{
case DIALOG_PICK_MENU:
case DIALOG_F10:
{
get_parm(2, button_text); /* get item name to search for */
fxt_item = trim(read());
_dialog_esc(); /* leave menu procedure */
}
}
returns(TRUE);
}
/*****************************************************************************/
/* dialog menu generation front end for fxt items */
/*****************************************************************************/
void _fxtxrefmenu(string fxt_func, string fxt_base, int first)
{
int menu_buf, dst_buf, old_buf_id, line, width, max_width;
int num_lines, num_cols, dos_ret;
string fxt_param, item, file, act_char;
item = "FFT";
fxt_item = fft_xref_item;
file = fft_xref;
max_width = fft_xrefmenuwidth;
if (first)
{
fxt_item = _extract_item();
if (!strlen(fxt_item))
return;
fft_xref_item = fxt_item;
if (exist(file))
del(file); /* delete file */
max_width = 0; /* reset value */
}
else if (!strlen(fxt_item))
{
message("No %s item specified", item);
return;
}
message("Building %s reference menu", item);
if (!exist(file)) /* if menu file does not exist, build it */
{
/* DATABASE SEARCH */
if (strlen(fxt_base))
fxt_param = "-f" + fxt_base + " ";
if (index(fxt_item, " "))
act_char = "\"" + fxt_item + "\""; /* quote the string */
else
act_char = fxt_item;
/* perform database search for cross references of item */
dos_ret = dos(fxt_func + " " + fxt_param + "-R" + act_char + " >&" + file);
if (dos_ret != 101)
{
message("No %s references for '%s' found", item, fxt_item);
del(file); /* delete file */
return;
}
/* sort file names */
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer(fxt_item, file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
top_of_buffer(); /* go to top */
dst_buf = create_buffer(TMPFILE, TMPFILE, 1);
max_width = 0; /* reset values */
line = 0;
while (!inq_position())
{
/* read line and insert it in sorted order */
fxt_item = read(); /* read line from source buffer */
delete_line(); /* and delete this line */
set_buffer(dst_buf); /* switch to destination buffer */
_fxt_insert_sorted(fxt_item, 1, line); /* insert sorted */
set_buffer(menu_buf); /* switch back to source buffer */
/* calculate line length */
width = strlen(substr(fxt_item, 1, rindex(fxt_item, "\t") - 1));
if (width > 1)
{
if (width > max_width)
max_width = width; /* store maximum */
}
/* increment counter and show message */
message("Building %s reference menu [#%d]", item, ++line);
}
/* store maximum line length for next call */
fft_xrefmenuwidth = max_width;
/* destination buffer contains the sorted source buffer */
/* ... now copy destination back to source buffer */
set_buffer(dst_buf); /* switch to destination buffer */
end_of_buffer(); /* go to end of buffer */
inq_position (num_lines, num_cols); /* get buffer end location */
set_buffer(menu_buf); /* switch to menu buffer */
top_of_buffer(); /* go to buffer start */
transfer(dst_buf, 1, 1, num_lines, num_cols); /* transfer buffer */
write_buffer(); /* write buffer to disk */
del(substr(file, 1, rindex(file, ".")) + "BAK"); /* delete backup */
delete_buffer(dst_buf); /* delete destination buffer */
del(TMPFILE); /* delete destination file */
}
else /* menu file exists, we have just to get the file */
{
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer(fxt_item, file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
}
end_of_buffer(); /* go to end of buffer */
next_char(1); /* go one character beyond the end because */
/* it must be one line more than items */
inq_position(line); /* get current position */
top_of_buffer(); /* go to top of buffer */
fxt_file = ""; /* reset variable */
fxt_line = 0;
if ((line > 1) && max_width) /* if any entries found */
{ /* start building dialog menu */
tabs(max_width + 3); /* set new tab size to split informations */
inq_screen_size(num_lines, num_cols);
if ((line += 3) > (num_lines - 5))
line = num_lines - 5;
if ((max_width += 8) < 15)
max_width = 15;
if (max_width >= num_cols - 3)
max_width = num_cols - 3;
max_width = (max_width + 1) / 2; /* calculate menu window sizes */
num_cols = (num_cols + 1 ) / 2;
set_buffer(old_buf_id); /* restore old buffer */
/* call dialog menu processing function */
_process_menu(num_cols - max_width,
line,
num_cols + max_width,
3,
NULL,
"",
NULL,
menu_buf, /* buffer to use for dialog menu */
"_fxt_xrefaction", /* function to perform on keystroke */
TRUE
);
}
else /* no entries found */
{
set_buffer(old_buf_id); /* restore old buffer */
message("No %s reference found", item);
}
delete_buffer(menu_buf); /* delete buffer from list */
if (strlen(fxt_file)) /* if item selected from menu */
_fxt_edit_file();
}
/*****************************************************************************/
/* registered macro to perform actions for menu keystrokes */
/*****************************************************************************/
int _fxt_xrefaction(int event_type, ...)
{
string button_text;
get_parm(NULL, event_type);
switch (event_type)
{
case DIALOG_PICK_MENU:
case DIALOG_F10:
{
get_parm(2, button_text); /* get item name to search for */
fxt_file = substr(button_text, 1, rindex(button_text, "\t") - 1);
fxt_line = atoi(substr(button_text, rindex(button_text, "\t") + 1));
_dialog_esc(); /* leave menu procedure */
}
}
returns(TRUE);
}
/*****************************************************************************/
/* dialog menu generation front end for file contents */
/*****************************************************************************/
void _fxtdefmenu(string fxt_func, string fxt_base)
{
int menu_buf, dst_buf, old_buf_id, line, width, max_width;
int num_lines, num_cols, dos_ret;
string fxt_param, item, file;
item = "FFT";
fxt_file = fft_def_item;
file = fft_deffile;
max_width = fft_defmenuwidth;
inq_names(fxt_item);
if (!strlen(fxt_item))
return;
if (!strlen(fxt_file) || (fxt_file != fxt_item))
{
fxt_file = fxt_item;
fft_def_item = fxt_file;
if (exist(file))
del(file); /* delete file */
max_width = 0; /* reset value */
}
message("Building %s file contents menu", item);
if (!exist(file)) /* if menu file does not exist, build it */
{
/* DATABASE SEARCH */
if (strlen(fxt_base))
fxt_param = "-f" + fxt_base + " ";
/* perform database search for cross references of item */
dos_ret = dos(fxt_func + " " + fxt_param + "-D" + fxt_file + " >&" + file);
if (dos_ret != 101)
{
_exec_error(dos_ret, "No %s items in '%s' found", item, fxt_file);
del(file); /* delete file */
return;
}
/* sort file names */
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer("File contents", file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
top_of_buffer(); /* go to top */
dst_buf = create_buffer(TMPFILE, TMPFILE, 1);
max_width = 0; /* reset values */
line = 0;
while (!inq_position())
{
/* read line and insert it in sorted order */
fxt_item = read(); /* read line from source buffer */
delete_line(); /* and delete this line */
set_buffer(dst_buf); /* switch to destination buffer */
_fxt_insert_sorted(fxt_item, 1, line); /* insert sorted */
set_buffer(menu_buf); /* switch back to source buffer */
/* calculate line length */
width = strlen(substr(fxt_item, 1, rindex(fxt_item, "\t") - 1));
if (width > 1)
{
if (width > max_width)
max_width = width; /* store maximum */
}
/* increment counter and show message */
message("Building %s file contents menu [#%d]", item, ++line);
}
/* store maximum line length for next call */
fft_defmenuwidth = max_width;
/* destination buffer contains the sorted source buffer */
/* ... now copy destination back to source buffer */
set_buffer(dst_buf); /* switch to destination buffer */
end_of_buffer(); /* go to end of buffer */
inq_position(num_lines, num_cols); /* get buffer end location */
set_buffer(menu_buf); /* switch to menu buffer */
top_of_buffer(); /* go to buffer start */
transfer(dst_buf, 1, 1, num_lines, num_cols); /* transfer buffer */
write_buffer(); /* write buffer to disk */
del(substr(file, 1, rindex(file, ".")) + "BAK"); /* delete backup */
delete_buffer(dst_buf); /* delete destination buffer */
del(TMPFILE); /* delete destination file */
}
else /* menu file exists, we have just to get the file */
{
old_buf_id = inq_buffer(); /* remember actual buffer */
menu_buf = create_buffer("File contents", file, 1); /* use generated file with items */
set_buffer(menu_buf); /* make actual buffer */
}
end_of_buffer(); /* go to end of buffer */
next_char(1); /* go one character beyond the end because */
/* it must be one line more than items */
inq_position(line); /* get current position */
top_of_buffer(); /* go to top of buffer */
fxt_line = 0;
if ((line > 1) && max_width) /* if any entries found */
{ /* start building dialog menu */
tabs(132); /* set new tab size to split informations */
inq_screen_size(num_lines, num_cols);
if ((line += 3) > (num_lines - 5))
line = num_lines - 5;
if ((max_width += 2) < 15)
max_width = 15;
if (max_width >= num_cols - 3)
max_width = num_cols - 3;
max_width = (max_width + 1) / 2; /* calculate menu window sizes */
num_cols = (num_cols + 1 ) / 2;
set_buffer(old_buf_id); /* restore old buffer */
/* call dialog menu processing function */
_process_menu(num_cols - max_width,
line,
num_cols + max_width,
3,
NULL,
"",
NULL,
menu_buf, /* buffer to use for dialog menu */
"_fxt_defaction", /* function to perform on keystroke */
TRUE
);
}
else /* no entries found */
{
set_buffer(old_buf_id); /* restore old buffer */
message("No %s file contents found", item);
}
delete_buffer(menu_buf); /* delete buffer from list */
if (fxt_line) /* if item selected from menu */
_fxt_edit_file();
}
/*****************************************************************************/
/* registered macro to perform actions for menu keystrokes */
/*****************************************************************************/
int _fxt_defaction(int event_type, ...)
{
string button_text;
get_parm(NULL, event_type);
switch (event_type)
{
case DIALOG_PICK_MENU:
case DIALOG_F10:
{
get_parm(2, button_text); /* get item name to search for */
fxt_line = atoi(substr(button_text, rindex(button_text, "\t") + 1));
_dialog_esc(); /* leave menu procedure */
}
}
returns(TRUE);
}
/*****************************************************************************/
/* function to insert text in lexicographical order, binary search */
/*****************************************************************************/
void _fxt_insert_sorted(string to_insert, int top, int bottom)
{
if (top <= bottom)
{
string line_text;
string name_ins, name_tmp;
int line_ins, line_tmp;
move_abs(bottom, 1);
line_text = read();
name_tmp = substr(line_text, 1, rindex(line_text, "\t") - 1);
line_tmp = atoi(substr(line_text, rindex(line_text, "\t") + 1));
name_ins = substr(to_insert, 1, rindex(to_insert, "\t") - 1);
line_ins = atoi(substr(to_insert, rindex(to_insert, "\t") + 1));
if ( (line_text != "\n")
&& ( (name_ins < name_tmp)
|| ((name_ins == name_tmp) && (line_ins < line_tmp))
)
)
{
int middle_line;
while (top < bottom)
{
middle_line = top + ((bottom - top) / 2);
move_abs(middle_line, 1);
line_text = read();
name_tmp = substr(line_text, 1, rindex(line_text, "\t") - 1);
line_tmp = atoi(substr(line_text, rindex(line_text, "\t") + 1));
if ( (name_ins < name_tmp)
|| ((name_ins == name_tmp) && (line_ins < line_tmp))
)
bottom = middle_line - 1;
else
top = middle_line + 1;
}
move_abs(top, 1);
line_text = read();
name_tmp = substr(line_text, 1, rindex(line_text, "\t") - 1);
line_tmp = atoi(substr(line_text, rindex(line_text, "\t") + 1));
if ( (line_text != "\n")
&& ( (name_ins > name_tmp)
|| ((name_ins == name_tmp) && (line_ins > line_tmp))
)
)
{
down();
}
}
else if (line_text != "\n")
down();
}
else
move_abs(top, 1);
insert(to_insert);
}
/*****************************************************************************/
/* extract and search for a cross reference number */
/*****************************************************************************/
void fxtsearchxref(void)
{
int move_flag;
string itemname, act_char, nchar;
nchar = "[0-9]";
if (!search_string(nchar, read(1)))
{
message("Invalid cursor position");
return;
}
message("");
save_position(); /* save the current position */
act_char = read(1); /* read current character */
while (search_string(nchar, act_char))
{
if (!prev_char(1))
{
move_flag = 1;
break;
}
act_char = read(1);
}
if (!search_string("[(]", act_char)) /* test first character */
{
message("Invalid cursor position");
restore_position();
return;
}
if (!move_flag)
next_char(1); /* one step forward */
act_char = read(1); /* read current character */
while (search_string(nchar, act_char))
{
itemname += act_char; /* generate search string */
next_char(1);
act_char = read(1);
}
itemname = "(" + itemname + ")";
message("Searching reference number %s", itemname);
goto_line(1); /* go to the beginning */
search_fwd(itemname); /* start search */
next_char(1); /* one step forward */
}
/**** THIS IS THE END THIS IS THE END THIS IS THE END THIS IS THE END ****/